package com.eastcom.providor.dao.impl;

import java.util.Date;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.eastcom.bm.atom.DataAbnormal;
import com.eastcom.canicula.stope.utils.DateUtil;
import com.eastcom.client.DataAbnormalBean;
import com.eastcom.common.util.CharliDate;
import com.eastcom.providor.dao.BaseDao;
import com.eastcom.providor.dao.IDataAbnormalDao;
import com.eastcom.providor.util.TimeSwap;

public class DataAbnormalDao extends BaseDao implements IDataAbnormalDao{

	public List<DataAbnormal> getAllDataAbnormals() throws Exception {
		List<DataAbnormal> l=
		this.getSQLObjects("select a.*,rownum id from QA_DATA_ABNORMAL a",DataAbnormal.class);
		return l;
	}

	public List<DataAbnormal> getAllDataAbnormals(Date start, Date end) {
		List<DataAbnormal> result=
			this.getSQLObjects("select a.*,rownum id from QA_DATA_ABNORMAL a where  (a.TIME_STAMP>=? and a.TIME_STAMP<?)",
					DataAbnormal.class,new Object[]{start,end});
			return result;
	}

	public List<DataAbnormal> getDataAbnormals(String datasetID, Date start, Date end) {
		List<DataAbnormal> result=
			this.getSQLObjects("select a.*,rownum id from QA_DATA_ABNORMAL a where a.DATASET_ID=? and  (a.TIME_STAMP>=? and a.TIME_STAMP<?)",
					DataAbnormal.class,new Object[]{datasetID,start,end});
			return result;
	}

	//从异常表中查出的记录进行封装，这样的好处是可以得到更详细的信息供界面呈现
	public List<DataAbnormalBean> getDataIntegerAbnormalBeanByParams(String datasetID, Date start, Date end)throws Exception{
		try{
			StringBuffer sql=new StringBuffer("select id,name_cn,base_integer_value,deviation from qa_dataset_define");
			Map<Object,Map> datasetMap=getFieldMapWithKeyFildBySQL(sql.toString(), "id", new String[]{"name_cn","base_integer_value","deviation"});
			
			String startDate=start==null?DateUtil.DateToString(datePattern, CharliDate.getStartTimeOfDaysApartCurrentDay(new Date(), -1)):
				DateUtil.DateToString(datePattern, start);
			String endDate=end==null?null:DateUtil.DateToString(datePattern, end);
			
			sql=new StringBuffer("select a.data_time,a.abnormal_type,a.value,a.kpi_id,a.dataset_id," +
					"a.time_stamp,a.abnormal_desc,a.ne_type,a.avg_historyvalue,a.integrity_ratio from qa_data_abnormal a ");
			boolean firstCondition=appendNotNullDateAfterCondition(sql, "a.time_stamp", startDate, true);
			firstCondition=appendNotNullDateBeforeCondition(sql, "a.time_stamp", endDate, firstCondition);
			appeandNotNullParam(sql, "a.dataset_id", datasetID, datasetID, "=", firstCondition);
//			appeandNotNullParam(sql, "a.state", "1", "1", "=", firstCondition);	//state字段应该是与指标准确性相关，不参与完整性判断
			appeandNotNullParam(sql, "a.abnormal_type", "4", "4", "=", firstCondition);	//注意，没有group by
			Map<Object,List<Map>> abnormalMap=this.getFieldMapLstWithKeyFildBySQL(sql.toString(), "dataset_id", 
					new String[]{"data_time","value","abnormal_type","kpi_id","time_stamp","abnormal_desc","ne_type","avg_historyvalue","integrity_ratio"});
			if(abnormalMap==null||abnormalMap.isEmpty())
				return null;
			
			List<DataAbnormalBean> dataAbnormalBeans=new LinkedList<DataAbnormalBean>();

			for(Object dataSetId:abnormalMap.keySet()){
				String dataSetName=datasetMap==null||datasetMap.get(dataSetId)==null?null:(String)datasetMap.get(dataSetId).get("name_cn");
				Object baseIntegerValue=datasetMap==null||datasetMap.get(dataSetId)==null?null:datasetMap.get(dataSetId).get("base_integer_value");
				Object deviation=datasetMap==null||datasetMap.get(dataSetId)==null?null:datasetMap.get(dataSetId).get("deviation");
				
				List<Map> setAbnormalDatas=abnormalMap.get(dataSetId);
				for(Map map:setAbnormalDatas){
					Double integrityRatio=map.get("integrity_ratio")==null?null:Double.parseDouble(map.get("integrity_ratio").toString());
					if(integrityRatio==null||integrityRatio>=100)
						continue;
					
					DataAbnormalBean dataAbnormalBean=new DataAbnormalBean();
					dataAbnormalBean.setDataSetName(dataSetName);
					dataAbnormalBean.setBusiness((String)map.get("ne_type"));
					dataAbnormalBean.setCheckDate((Date)map.get("data_time"));
					dataAbnormalBean.setDataSetId((String)dataSetId);
					dataAbnormalBean.setDesc((String)map.get("abnormal_desc"));
					dataAbnormalBean.setKpiId((String)map.get("kpi_id"));
					dataAbnormalBean.setTimeStamp((Date)map.get("time_stamp"));
					dataAbnormalBean.setValue(map.get("value")==null?null:map.get("value").toString());
					dataAbnormalBean.setAvgHistoryValue(map.get("avg_historyvalue")==null?null:map.get("avg_historyvalue").toString());

					String validateDesc="基准值"+baseIntegerValue+",浮动范围:"+deviation+"%";
					dataAbnormalBean.setValidateDesc(validateDesc);
					dataAbnormalBean.setAbnoarmalType("完整性异常");
					dataAbnormalBean.setValidateType((String)map.get("abnormal_type"));
					dataAbnormalBean.setBaseIntegerValue(baseIntegerValue==null?null:Double.parseDouble(baseIntegerValue.toString()));
					dataAbnormalBean.setDeviation(deviation==null?null:Double.parseDouble(deviation.toString()));
					dataAbnormalBeans.add(dataAbnormalBean);
				}
			}
			
			return dataAbnormalBeans;
		}
		catch(Exception e){
			throw e;
		}
	}

	public List<DataAbnormalBean> getDataAbnormalBeanByParams(String datasetID, Date start, Date end, int startRow, int endRow) throws Exception {
		//int startRow=page*numPerpage+1;
		//int endRow=page*numPerpage+numPerpage;
		
		try{
			StringBuffer sql=new StringBuffer("select id,name_cn,base_integer_value,deviation from qa_dataset_define");
			Map<Object,Map> datasetMap=getFieldMapWithKeyFildBySQL(sql.toString(), "id", new String[]{"name_cn","base_integer_value","deviation"});
			
			String startDate=start==null?DateUtil.DateToString(datePattern, CharliDate.getStartTimeOfDaysApartCurrentDay(new Date(), -1)):
				DateUtil.DateToString(datePattern, start);
			String endDate=end==null?null:DateUtil.DateToString(datePattern, end);
			
			sql=new StringBuffer("select s.* from(select s1.*,rownum rn from(" +
					"select a.data_time,a.abnormal_type,a.value,a.kpi_id,a.dataset_id," +
					"a.time_stamp,a.abnormal_desc,a.ne_type,a.avg_historyvalue,a.integrity_ratio,a.ne_id from qa_data_abnormal a ");
			boolean firstCondition=appendNotNullDateAfterCondition(sql, "a.time_stamp", startDate, true);
			firstCondition=appendNotNullDateBeforeCondition(sql, "a.time_stamp", endDate, firstCondition);
			firstCondition=appeandNotNullParam(sql, "a.dataset_id", datasetID, datasetID, "=", firstCondition);
			firstCondition=appeandNotNullParam(sql, "a.state", "1", "1", "=", firstCondition);
            appeandExpressWhenValueNotNull(sql, "a.integrity_ratio", "100", "100", "<>", firstCondition);
			sql.append(" order by a.time_stamp desc) s1) s where rn>="+startRow+" and rn<="+endRow);
			Map<Object,List<Map>> abnormalMap=this.getFieldMapLstWithKeyFildBySQL(sql.toString(), "dataset_id", 
					new String[]{"data_time","value","abnormal_type","kpi_id","time_stamp","abnormal_desc","ne_type","avg_historyvalue","integrity_ratio","ne_id"});
			if(abnormalMap==null||abnormalMap.isEmpty())
				return null;
			
			List<DataAbnormalBean> dataAbnormalBeans=new LinkedList<DataAbnormalBean>();
			Set<String> dataSetkpiIds=new HashSet<String>();
			
			for(Object dataSetId:abnormalMap.keySet()){
				String dataSetName=datasetMap==null||datasetMap.get(dataSetId)==null?null:(String)datasetMap.get(dataSetId).get("name_cn");
				Object baseIntegerValue=datasetMap==null||datasetMap.get(dataSetId)==null?null:datasetMap.get(dataSetId).get("base_integer_value");
				Object deviation=datasetMap==null||datasetMap.get(dataSetId)==null?null:datasetMap.get(dataSetId).get("deviation");
				
				List<Map> setAbnormalDatas=abnormalMap.get(dataSetId);
				for(Map map:setAbnormalDatas){
					DataAbnormalBean dataAbnormalBean=new DataAbnormalBean();
					dataAbnormalBean.setDataSetName(dataSetName);
					dataAbnormalBean.setBusiness((String)map.get("ne_type"));
					dataAbnormalBean.setCheckDate((Date)map.get("data_time"));
					dataAbnormalBean.setDataSetId((String)dataSetId);
					dataAbnormalBean.setDesc((String)map.get("abnormal_desc"));
					dataAbnormalBean.setKpiId((String)map.get("kpi_id"));
					dataAbnormalBean.setNeId((String)map.get("ne_id"));
					dataAbnormalBean.setTimeStamp((Date)map.get("time_stamp"));
					dataAbnormalBean.setValue(map.get("value")==null?null:map.get("value").toString());
					dataAbnormalBean.setAvgHistoryValue(map.get("avg_historyvalue")==null?null:map.get("avg_historyvalue").toString());
					
					String abnoarmalType,validateDesc=null;
					if("4".equals(map.get("abnormal_type"))){
						Double integrityRatio=map.get("integrity_ratio")==null?null:Double.parseDouble(map.get("integrity_ratio").toString());
						if(integrityRatio==null||integrityRatio==100)
							continue;
						
						abnoarmalType="完整性异常";
						validateDesc="基准值"+baseIntegerValue+",浮动范围:"+deviation+"%";
						dataAbnormalBean.setValidateDesc(validateDesc);
					}
					else
						abnoarmalType="准确性异常";

					dataAbnormalBean.setAbnoarmalType(abnoarmalType);
					dataAbnormalBean.setValidateType((String)map.get("abnormal_type"));
					
					dataAbnormalBeans.add(dataAbnormalBean);
					if(map.get("kpi_id")!=null)
						dataSetkpiIds.add("('"+(String)map.get("kpi_id")+"','"+dataSetId+"')");
				}
			}
			
			sql=new StringBuffer("select k.kpi_id,k.name_cn,k.dataset_id,k.validation_type," +
					"k.baseline_value,k.deviation_up,k.deviation_down,k.threadhold_up,k.threadhold_down from qa_kpi_define k ");
			mergeSQLbyUnionFieldLst(sql, "(k.kpi_id,k.dataset_id)", dataSetkpiIds, true);
			Map<Object,Map> kpiInfoMap=getFieldMapLstWithKeyFildsBySQL(sql.toString(),new String[]{"kpi_id","dataset_id"},new String[]{"name_cn","validation_type","baseline_value","deviation_up","deviation_down","threadhold_up","threadhold_down"});
			
			for(DataAbnormalBean dataAbnormalBean:dataAbnormalBeans){
				if("4".equals(dataAbnormalBean.getValidateType()))
					continue;
				
				Map kpiMap=kpiInfoMap==null?null:kpiInfoMap.get(dataAbnormalBean.getKpiId()+"@#"+dataAbnormalBean.getDataSetId()+"@#");
				if(kpiMap==null)
					continue;
				
				dataAbnormalBean.setKpiName((String)kpiMap.get("name_cn"));
				if("0".equals(dataAbnormalBean.getValidateType()))
					dataAbnormalBean.setValidateDesc("门限范围["+kpiMap.get("threadhold_up")+","+kpiMap.get("threadhold_down")+"]");
				else if("1".equals(dataAbnormalBean.getValidateType()))
					dataAbnormalBean.setValidateDesc("基准值"+kpiMap.get("baseline_value")+",上偏离范围"+kpiMap.get("deviation_up")+"%,下偏离范围"+kpiMap.get("deviation_down")+"%");
				else
					dataAbnormalBean.setValidateDesc("上偏离范围"+kpiMap.get("deviation_up")+"%,下偏离范围"+kpiMap.get("deviation_down")+"%");
			}
			
			return dataAbnormalBeans;
		}
		catch(Exception e){
			throw e;
		}
	}

	public List<DataAbnormalBean> getDataAbnormalBeanByParams(String datasetID, Date start, Date end)throws Exception {
		try{
			StringBuffer sql=new StringBuffer("select id,name_cn,base_integer_value,deviation from qa_dataset_define");
			Map<Object,Map> datasetMap=getFieldMapWithKeyFildBySQL(sql.toString(), "id", new String[]{"name_cn","base_integer_value","deviation"});
			
			String startDate=start==null?DateUtil.DateToString(datePattern, CharliDate.getStartTimeOfDaysApartCurrentDay(new Date(), -1)):
				DateUtil.DateToString(datePattern, start);
			String endDate=end==null?null:DateUtil.DateToString(datePattern, end);
			
			sql=new StringBuffer("select a.data_time,a.abnormal_type,a.value,a.kpi_id,a.dataset_id," +
					"a.time_stamp,a.abnormal_desc,a.ne_type,a.avg_historyvalue,a.integrity_ratio,a.ne_id from qa_data_abnormal a ");
			boolean firstCondition=appendNotNullDateAfterCondition(sql, "a.time_stamp", startDate, true);
			firstCondition=appendNotNullDateBeforeCondition(sql, "a.time_stamp", endDate, firstCondition);
			firstCondition=appeandNotNullParam(sql, "a.dataset_id", datasetID, datasetID, "=", firstCondition);
			firstCondition=appeandNotNullParam(sql, "a.state", "1", "1", "=", firstCondition);
			appeandExpressWhenValueNotNull(sql, "a.integrity_ratio", "100", "100", "<>", firstCondition);
			sql.append(" order by a.time_stamp");
			Map<Object,List<Map>> abnormalMap=this.getFieldMapLstWithKeyFildBySQL(sql.toString(), "dataset_id", 
					new String[]{"data_time","value","abnormal_type","kpi_id","time_stamp","abnormal_desc","ne_type","avg_historyvalue","integrity_ratio","ne_id"});
			if(abnormalMap==null||abnormalMap.isEmpty())
				return null;
			
			List<DataAbnormalBean> dataAbnormalBeans=new LinkedList<DataAbnormalBean>();
			Set<String> dataSetkpiIds=new HashSet<String>();
			
			for(Object dataSetId:abnormalMap.keySet()){
				String dataSetName=datasetMap==null||datasetMap.get(dataSetId)==null?null:(String)datasetMap.get(dataSetId).get("name_cn");
				Object baseIntegerValue=datasetMap==null||datasetMap.get(dataSetId)==null?null:datasetMap.get(dataSetId).get("base_integer_value");
				Object deviation=datasetMap==null||datasetMap.get(dataSetId)==null?null:datasetMap.get(dataSetId).get("deviation");
				
				List<Map> setAbnormalDatas=abnormalMap.get(dataSetId);
				for(Map map:setAbnormalDatas){
					DataAbnormalBean dataAbnormalBean=new DataAbnormalBean();
					dataAbnormalBean.setDataSetName(dataSetName);
					dataAbnormalBean.setBusiness((String)map.get("ne_type"));
					dataAbnormalBean.setCheckDate((Date)map.get("data_time"));
					dataAbnormalBean.setDataSetId((String)dataSetId);
					dataAbnormalBean.setDesc((String)map.get("abnormal_desc"));
					dataAbnormalBean.setKpiId((String)map.get("kpi_id"));
					dataAbnormalBean.setNeId((String)map.get("ne_id"));
					dataAbnormalBean.setTimeStamp((Date)map.get("time_stamp"));
					dataAbnormalBean.setValue(map.get("value")==null?null:map.get("value").toString());
					dataAbnormalBean.setAvgHistoryValue(map.get("avg_historyvalue")==null?null:map.get("avg_historyvalue").toString());
					dataAbnormalBean.setBaseIntegerValue(baseIntegerValue==null?null:Double.parseDouble(baseIntegerValue.toString()));
					dataAbnormalBean.setDeviation(deviation==null?null:Double.parseDouble(deviation.toString()));
					
					String abnoarmalType,validateDesc=null;
					if("4".equals(map.get("abnormal_type"))){
						Double integrityRatio=map.get("integrity_ratio")==null?null:Double.parseDouble(map.get("integrity_ratio").toString());
						if(integrityRatio==null||integrityRatio==100)
							continue;
						
						abnoarmalType="完整性异常";
						validateDesc="基准值"+baseIntegerValue+",浮动范围:"+deviation+"%";
						dataAbnormalBean.setValidateDesc(validateDesc);
					}
					else
						abnoarmalType="准确性异常";

					dataAbnormalBean.setAbnoarmalType(abnoarmalType);
					dataAbnormalBean.setValidateType((String)map.get("abnormal_type"));
					
					dataAbnormalBeans.add(dataAbnormalBean);
					if(map.get("kpi_id")!=null)
						dataSetkpiIds.add("('"+(String)map.get("kpi_id")+"','"+dataSetId+"')");
				}
			}
			
			sql=new StringBuffer("select k.kpi_id,k.name_cn,k.dataset_id,k.validation_type," +
					"k.baseline_value,k.deviation_up,k.deviation_down,k.threadhold_up,k.threadhold_down from qa_kpi_define k ");
			mergeSQLbyUnionFieldLst(sql, "(k.kpi_id,k.dataset_id)", dataSetkpiIds, true);
			Map<Object,Map> kpiInfoMap=getFieldMapLstWithKeyFildsBySQL(sql.toString(),new String[]{"kpi_id","dataset_id"},new String[]{"name_cn","validation_type","baseline_value","deviation_up","deviation_down","threadhold_up","threadhold_down"});
			
			for(DataAbnormalBean dataAbnormalBean:dataAbnormalBeans){
				if("4".equals(dataAbnormalBean.getValidateType()))
					continue;
				
				Map kpiMap=kpiInfoMap==null?null:kpiInfoMap.get(dataAbnormalBean.getKpiId()+"@#"+dataAbnormalBean.getDataSetId()+"@#");
				if(kpiMap==null)
					continue;
				
				//String validationDesc=null;
				dataAbnormalBean.setKpiName((String)kpiMap.get("name_cn"));
				if("0".equals(dataAbnormalBean.getValidateType()))
					dataAbnormalBean.setValidateDesc("门限范围["+kpiMap.get("threadhold_up")+","+kpiMap.get("threadhold_down")+"]");
				else if("1".equals(dataAbnormalBean.getValidateType()))
					dataAbnormalBean.setValidateDesc("基准值"+kpiMap.get("baseline_value")+",上偏离范围"+kpiMap.get("deviation_up")+"%,下偏离范围"+kpiMap.get("deviation_down")+"%");
				else
					dataAbnormalBean.setValidateDesc("上偏离范围"+kpiMap.get("deviation_up")+"%,下偏离范围"+kpiMap.get("deviation_down")+"%");
			}
			
			return dataAbnormalBeans;
		}
		catch(Exception e){
			throw e;
		}
		
	}

	public int getCountDataAbnormalBeanByParams(String datasetID, Date start, Date end)throws Exception {
		try{
			StringBuffer sql=new StringBuffer("select id,name_cn,base_integer_value,deviation from qa_dataset_define");
			Map<Object,Map> datasetMap=getFieldMapWithKeyFildBySQL(sql.toString(), "id", new String[]{"name_cn","base_integer_value","deviation"});
			
			String startDate=start==null?DateUtil.DateToString(datePattern, CharliDate.getStartTimeOfDaysApartCurrentDay(new Date(), -1)):
				DateUtil.DateToString(datePattern, start);
			String endDate=end==null?null:DateUtil.DateToString(datePattern, end);
			
			sql=new StringBuffer("select count(*) as num from qa_data_abnormal a ");
			boolean firstCondition=appendNotNullDateAfterCondition(sql, "a.time_stamp", startDate, true);
			firstCondition=appendNotNullDateBeforeCondition(sql, "a.time_stamp", endDate, firstCondition);
			firstCondition=appeandNotNullParam(sql, "a.dataset_id", datasetID, datasetID, "=", firstCondition);
			firstCondition=appeandNotNullParam(sql, "a.state", "1", "1", "=", firstCondition);
			appeandExpressWhenValueNotNull(sql, "a.integrity_ratio", "100", "100", "<>", firstCondition);
			List<Map> numMap=this.getFieldsBySQL(sql.toString(), new String[]{"num"});
            return numMap==null||numMap.isEmpty()?0:Integer.parseInt(numMap.get(0).get("num").toString());
		}
		catch(Exception e){
			throw e;
		}
		
	}
	
	public void removeDataAbnormal(String dataSetId, String kpiId, String neId,Date timeStamp) throws Exception {
		try{
			//String dataTime=DateUtil.DateToString(datePattern, timeStamp);
			
			executeUpdate("update DataAbnormal set state='0' where " +
					"datasetId='"+dataSetId+"' and kpiId='"+kpiId+"'and neId='"+neId+"' and timeStamp=?", new Object[]{timeStamp});
			
			//executeSqlUpdate("update qa_raw_data set is_normal='1',value="+value+" where " +
					//"dataset_id='"+dataSetId+"' and kpi_id='"+kpiId+"' " +
					//"and ne_id='"+neId+"' and timeStamp=to_date('"+dataTime+"','yyyy-mm-dd hh24:mi:ss')", null);
		}
		catch(Exception e){
			throw e;
		}
	}

	public void removeIntegerAbnormal(String dataSetId, Date timeStamp) throws Exception {
		try{
			this.executeUpdate("update DataAbnormal set state='0' where " +
					"datasetId='"+dataSetId+"' and abnormalType='4' and timeStamp=?", new Object[]{timeStamp});
		}
		catch(Exception e){
			throw e;
		}
	}
	
	public void removeIntegerAbnormals(String dataSetId, List<Date> timeStamps) throws Exception {
		try{
			List<String> timeExps=new LinkedList<String>();
			
			for(Date timeStamp:timeStamps)
				timeExps.add("to_date('"+DateUtil.DateToString(datePattern, timeStamp)+"','yyyy-mm-dd hh24:mi:ss')");
			
			StringBuffer sql=new StringBuffer("update qa_data_abnormal set state='0' where dataset_id='"+dataSetId+"'");
			mergeSQLbyUnionFieldLst(sql, "TIME_STAMP", timeExps, false);
			executeSqlUpdate(sql.toString(), null);
		}
		catch(Exception e){
			throw e;
		}
	}
	
	public void removeIntegerAbnormalByDataSetTimeStampExp(List<String> dataSetTimeStamp) throws Exception {
		if(dataSetTimeStamp==null||dataSetTimeStamp.isEmpty())
			return;
		
		try{
			StringBuffer sql=new StringBuffer("update qa_data_abnormal set state='0'");
			mergeSQLbyUnionFieldLst(sql, "(DATASET_ID,TIME_STAMP)", dataSetTimeStamp, true);
			executeSqlUpdate(sql.toString(), null);
		}
		catch(Exception e){
			throw e;
		}
	}
	
	public void updateDataAbnormalByScanMap(Map<String,String> scanMap,Date updataDate) throws Exception
	{
		String sUpdateDate=TimeSwap.swap(updataDate, TimeSwap.ORACLE_TYPE);
		StringBuffer sql=null;
		if(Boolean.valueOf(scanMap.get("isInteger")))
		{
			//完整 当前维度个数:67 完整性基准值:67.0 偏离范围 1.0%
			sql=new StringBuffer("update qa_data_abnormal set abnormal_desc='")
			.append("完整 ->>当前维度个数:").append(scanMap.get("currentDimensionNum")).append(" 完整性基准值:")
			.append(scanMap.get("baseInteger")).append(" 偏离范围 ").append(scanMap.get("deviation")).append("'")
			.append(" ,dimension_num=").append(scanMap.get("currentDimensionNum")).append(",integrity_ratio=").append(scanMap.get("integerRatio"))
			.append(" ,data_time=").append(sUpdateDate)
			.append(" where ABNORMAL_TYPE='4' and (DATASET_ID,TIME_STAMP) in (").append(scanMap.get("datasetid_timeStamp")).append(")");
		}else
		{
			//不完整 当前维度个数 7 完整性基准值 16.0 偏离范围 1.0%
			sql=new StringBuffer("update qa_data_abnormal set abnormal_desc='").append("不完整 ->>当前维度个数 ").append(scanMap.get("currentDimensionNum")).append(" 完整性基准值:")
			.append(scanMap.get("baseInteger")).append(" 偏离范围 ").append(scanMap.get("deviation")).append("'")
			.append(" ,dimension_num=").append(scanMap.get("currentDimensionNum")).append(",integrity_ratio=").append(scanMap.get("integerRatio"))
			.append(" ,data_time=").append(sUpdateDate)
			.append(" where ABNORMAL_TYPE='4' and (DATASET_ID,TIME_STAMP) in (").append(scanMap.get("datasetid_timeStamp")).append(")");
		}
		executeSqlUpdate(sql.toString(), null);
	}
	
	public Date selectMaxTimeByDatasetId(String dataset_id) throws Exception
	{
		String hql="select max(timeStamp) from DataAbnormal where datasetId=?";
		List result=this.getObjects(hql, new Object[]{dataset_id});
		return (Date)(result.get(0));
	}
}



